<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head lang="en">
    <th:block th:include="include :: header('首页')"/>
    <th:block th:include="include :: headertable"/>
</head>
<body>

<div id="toolbar">
    <button id="addAuthRole" class="layui-btn">+ 添加</button>
</div>

<table id="dataTable" lay-filter="dataTable" class="layui-table"></table>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: footertable"/>
<script>
    layui.use(['table', 'form'], function () {
        var table = layui.table;
        var form = layui.form;
        form.on('submit(sreach)', function (data) {
            config.tableQuery("dataTable", data.field)
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        function operateFormatter(value, row, index) {
            var operateHtml = new Array();
            operateHtml.push('<button data-method="confirmTrans" class="layui-btn layui-btn-sm" id="edit" ><i class="layui-icon">&#xe642;</i>编辑</button>');
            operateHtml.push('<button class="layui-btn layui-btn-sm layui-btn-danger" id="delete" ><i class="layui-icon">&#xe640;</i>删除</button>');
            return operateHtml.join('');
        }

        var operateEvents = {
            'click #edit': function (e, value, row, index) {
                json = row;
                config.openPageLayer("编辑", "device/addDeviceClass", ['500px', '400px'], "", false);
            },
            'click #delete': function (e, value, row, index) {
                json = row;
                config.openConfirmLayer("确定删除吗？", "/ht/deviceClassDel.json", {"id": row.id}, function (data) {
                    config.tableRefresh();
                })
            },
        };

        config.initTable("#dataTable", "/ht/deviceClassList.json", [ //表头
                {field: 'id', title: 'ID'}
                , {field: 'className', title: '分类名称'}
                , {field: 'code', title: '编码'}
                , {field: 'createTime', title: '添加时间'}
                , {field: 'updateTime', title: '更新时间'}
                , {title: '操作', events: operateEvents, formatter: operateFormatter}]
            , {});

        $(document).on('click', '#addAuthRole', function () {
            json = {};
            config.openPageLayer("添加分类", 'device/addDeviceClass', ['500px', '400px'], "", false);
        })
    })
</script>

</body>
</html>
